﻿///***************************************************************
/// 시  스  템 : Updms.Crd
/// 단위시스템 : CRD
/// 계      층 : Presentation Layer
/// 프로그램명 : Crd3010p
/// 파  일  명 : Crd3010p.aspx.cs
/// 설      명 : 카드대쉬보드
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-08-11 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Adapter;
using SMFramework.Data;
using SMFramework.Security;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.SMGridView;

using Base.AppFramework.Web.UI.CommandBar;
using Base.Dac;

using Updms.Common.BaseClass;
using Updms.Crd.Exe;


namespace Updms.Crd
{
	public partial class Crd3010p : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Crd3010p";
		public static readonly string gs_path_info = "/updms/Crd/" + PID + ".aspx";

		Global global = new Global();
		Crypto crypto = new Crypto();
		CommCode.Crd crd = new CommCode.Crd(LANG_SET);

		//검색
		protected string kw1 = "";	// 카드코드
		protected string kw2 = "";	// 시작일
		protected string kw3 = "";	// 종료일
		protected string kw4 = "";	// 미반영코드
		protected string kw5 = "";	// 미반영아이디
		protected string kw6 = "";	// 결제예정일

		//항목별리스트 합계
		decimal ld_pre_total = 0;	//전월
		decimal ld_this_total = 0;	//당월
		decimal ld_diff_total = 0;	//차액

		//페이지모드
		private string gs_page_mode = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SelectProcess();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetCardInfo();
			SetPaymntDtList(ddl_card_cd.SelectedValue);
			SetImportantAccount();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion		

		#region SetInit, SetSearchParameter, ShowKeywordLabel

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";

			gs_page_mode = (Request.QueryString["page_mode"] == null || Request.QueryString["page_mode"].Trim().Length == 0)
					? "" : Request.QueryString["page_mode"].ToString();	
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))	// url에 값이 없으면
					{
						kw1 = ddl_card_cd.SelectedValue;
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						ddl_card_cd.SelectedValue = kw1;
					}
					
					if (String.IsNullOrEmpty(Request.QueryString["kw6"]))	// url에 값이 없으면
					{
						kw6 = ddl_paymnt_dt.SelectedValue;
					}
					else
					{
						kw6 = Server.UrlDecode(Request.QueryString["kw6"]);
						ddl_paymnt_dt.SelectedValue = kw6;
					}
					
					kw2 = DateUtil.GetCalcMonth(ddl_paymnt_dt.SelectedValue.Substring(0, 7), -6, "yyyy-MM");	//결제일로부터 6개월전
					kw3 = DateUtil.GetCalcMonth(ddl_paymnt_dt.SelectedValue.Substring(0, 7), 3, "yyyy-MM");	//결제일로부터 3개월후
					kw4 = cb_support_yn.Checked ? "CRD" : "";
					kw5 = cb_support_yn.Checked ? "AG" : "";
					
					break;
				case "SEARCH":
					kw1 = ddl_card_cd.SelectedValue;
					kw6 = ddl_paymnt_dt.SelectedValue;
					kw2 = DateUtil.GetCalcMonth(ddl_paymnt_dt.SelectedValue.Substring(0, 7), -6, "yyyy-MM");	//결제일로부터 6개월전
					kw3 = DateUtil.GetCalcMonth(ddl_paymnt_dt.SelectedValue.Substring(0, 7), 3, "yyyy-MM");	//결제일로부터 3개월후
					kw4 = cb_support_yn.Checked ? "CRD" : "";
					kw5 = cb_support_yn.Checked ? "AG" : "";
					break;
			}
		}	

		#endregion

		#region 마스터 Method (SetCardInfo, SetPaymntDtList, SelectPaymntDt, SetAccount)

		//카드코드 변경시
		private void ddl_card_cd_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			SetPaymntDtList(ddl_card_cd.SelectedValue);
		}

		//카드정보
		private void SetCardInfo()
		{
			DataSet lo_ds = new DataSet();
			Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT();

			lo_ds.Merge(_Crd1010m_NT.GetCardInfoList("Y"));

			ddl_card_cd.Items.Clear();
			ddl_card_cd.DataSource = lo_ds;
			ddl_card_cd.DataMember = "UPDMS_CRD_INFO";
			ddl_card_cd.DataTextField = "Card_Nm";
			ddl_card_cd.DataValueField = "Card_Cd";
			ddl_card_cd.DataBind();

			//카드명세서에서 넘어온 경우
			if (!String.IsNullOrEmpty(Request.QueryString["kw1"]))	// url에 값이 있으면
			{
				ddl_card_cd.SelectedValue = Server.UrlDecode(Request.QueryString["kw1"]);
			}
		}

		//결제예정일리스트
		private void SetPaymntDtList(string ls_card_cd)
		{
			DataSet lo_ds = new DataSet();
			Crd1011m_NT _Crd1011m_NT = new Crd1011m_NT();

			lo_ds.Merge(_Crd1011m_NT.GetPaymntDtList(ls_card_cd));

			ddl_paymnt_dt.Items.Clear();
			ddl_paymnt_dt.DataSource = lo_ds;
			ddl_paymnt_dt.DataMember = "UPDMS_CRD_PAYMNT_DT";
			ddl_paymnt_dt.DataTextField = "Text";
			ddl_paymnt_dt.DataValueField = "Value";
			ddl_paymnt_dt.DataBind();

			SelectPaymntDt();
		}

		//오늘을 기준으로 결제일자 선택
		private void SelectPaymntDt()
		{
			int li_today = Convert.ToInt32(DateUtil.GetMonthEx(0, "yyyyMMdd"));
			int ddl_cnt = ddl_paymnt_dt.Items.Count;
			bool lb_no_paymnt_dt = true;

			for (int i = 0; i < ddl_cnt; i++)
			{
				if (li_today < ConversionUtil.ExtractNumberInt(ddl_paymnt_dt.Items[i].Text))
				{
					ddl_paymnt_dt.SelectedIndex = i;
					i = ddl_cnt;
					lb_no_paymnt_dt = false;
				}
			}

			//없으면 가장 최근의 결제일자로 셋팅
			if (lb_no_paymnt_dt)
			{
				ddl_paymnt_dt.SelectedIndex = ddl_cnt - 1;
			}
		}

		//계정
		private void SetImportantAccount()
		{
			crd.SetImportantAccount(cbl_search_account);
			WebControlUtil.SelectCheckBoxList(cbl_search_account, true);
		}

		//카드코드 변경시
		protected void ddl_card_cd_SelectedIndexChanged1(object sender, EventArgs e)
		{
			SetPaymntDtList(ddl_card_cd.SelectedValue);
		}

		#endregion

		#region 디테일 Method (1)

		#region 결제총액챠트

		//결제총액챠트
		private void DrawMonthlyTotalAmtChart()
		{
			chart_monthly_total_amt.Data.Series = 1;
			string ls_paymnt_dt = "'" + kw6.Substring(2, 5).Replace("-", ".");//비교할기준월 2008-06-11 -> '08-06

			//CustomGridLine
			ChartFX.WebForms.CustomGridLine cgl1 = new ChartFX.WebForms.CustomGridLine();
			cgl1.Value = 1000000;	//일백만원
			cgl1.Color = System.Drawing.Color.Red;
			cgl1.Width = 1;
			chart_monthly_total_amt.AxisY.CustomGridLines.Add(cgl1);

			using (Crd3010p_NT _Crd3010p_NT = new Crd3010p_NT())
			{
				DataSet lo_ds = new DataSet();
				DataPack lo_dp = new DataPack();

				lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
				lo_dp.AddProperty("ls_from_dt", typeof(string), kw2);
				lo_dp.AddProperty("ls_to_dt", typeof(string), kw3);
				lo_dp.AddProperty("ls_exc_sys_id", typeof(string), kw4);
				lo_dp.AddProperty("ls_exc_prefix", typeof(string), kw5);

				lo_ds.Merge(_Crd3010p_NT.GetMonthlyTotalAmtListOnDashboard(lo_dp));

				int li_count = DataSetUtil.GetRowCount(lo_ds, "UPDMS_CRD_REPORT");

				for (int i = 0; i < li_count; i++)
				{
					//수동으로 데이터 바인딩
					chart_monthly_total_amt.Data[0, i] = DataSetUtil.GetFldInt(lo_ds, "UPDMS_CRD_REPORT", i, "Total_Amt");

					//X축 라벨링
					chart_monthly_total_amt.AxisX.Labels[i]
						= "'" + DataSetUtil.GetFldStr(lo_ds, "UPDMS_CRD_REPORT", i, "Base_Dt").Replace("-", ".").Substring(2, 5);

					//당월챠트 구분되도록
					if (chart_monthly_total_amt.AxisX.Labels[i] == ls_paymnt_dt)
					{
						chart_monthly_total_amt.Points[0, i].Color = System.Drawing.Color.BlueViolet;
					}
					else
					{
						chart_monthly_total_amt.Points[0, i].Color = System.Drawing.Color.Plum;
					}

					//0은 안보여준다
					chart_monthly_total_amt.Points[0, i].PointLabels.Visible = (chart_monthly_total_amt.Data[0, i] > 0);
				}
			}//using
		}

		#endregion

		#region 주요계정별챠트(월간)

		//주요계정별챠트
		private void DrawMonthlyAccountChart()
		{
			int li_line_cnt = 0; // 그래프 라인수
			DataPack lo_dp = new DataPack();

			//챠트 초기화
			chart_account.Data.Series = WebControlUtil.GetCheckedItemsCount(cbl_search_account);

			string ls_paymnt_dt = "'" + kw6.Substring(2, 5).Replace("-", ".");//비교할기준월 2008-06-11 -> '08-06

			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_base_st_dt", typeof(string), kw2);
			lo_dp.AddProperty("ls_base_ed_dt", typeof(string), kw3);
			lo_dp.AddProperty("ls_account", typeof(string));	//선언만

			for (int i = 0; i < cbl_search_account.Items.Count; i++)
			{
				using (Crd2012r_NT _Crd2012r_NT = new Crd2012r_NT())
				{
					DataSet lo_ds = new DataSet();

					lo_dp["ls_account"] = cbl_search_account.Items[i].Value;

					//Base.AppFramework.SMEventLog.WriteDataLog("DrawMonthlyAccountChart", lo_dp);

					lo_ds.Merge(_Crd2012r_NT.GetMonthlyTotalAmtListByAccount(lo_dp));

					int li_count = DataSetUtil.GetRowCount(lo_ds, "UPDMS_CRD_REPORT");

					for (int j = 0; j < li_count; j++)
					{
						//수동으로 데이터 바인딩
						chart_account.Data[li_line_cnt, j] = DataSetUtil.GetFldInt(lo_ds, "UPDMS_CRD_REPORT", j, "Total_Amt");

						//X축 라벨링
						chart_account.AxisX.Labels[j]
							= "'" + DataSetUtil.GetFldStr(lo_ds, "UPDMS_CRD_REPORT", j, "Base_Dt").Replace("-", ".").Substring(2, 5);

						//당월챠트 구분되도록
						if (chart_account.AxisX.Labels[j] == ls_paymnt_dt)
						{
							chart_account.Points[li_line_cnt, j].PointLabels.Visible = true;
						}
						else
						{
							chart_account.Points[li_line_cnt, j].PointLabels.Visible = false;
						}
					}

					//시리즈
					chart_account.Series[li_line_cnt].Text = cbl_search_account.Items[i].Text;

					chart_account.Series[li_line_cnt].MarkerShape = ChartFxUtil.markerShape(li_line_cnt);

					li_line_cnt = li_line_cnt + 1;
				}//using
			}//for
		}

		#endregion

		#region 주요아이템

		//주요아이템
		private void SetImportantItemList()
		{
			DataSet lo_ds = new DataSet();
			Crd3010p_NT _Crd3010p_NT = new Crd3010p_NT();

			lo_ds.Merge(_Crd3010p_NT.GetImportantItemList());

			gv_important_item_list.DataSource = lo_ds;
			gv_important_item_list.DataBind();
		}

		//실제파일생성
		private void CreateFileReal(string ls_file_nm, DataSet ds)
		{
			try
			{
				string tableName = "UPDMS_CRD_REPORT";
				string ls_stream = FILE_PATH_FTP_UPLOAD + "\\" + ls_file_nm;
				FileInfo file = new FileInfo(ls_stream);

				StreamWriter sw = file.CreateText();

				sw.WriteLine(CommUtil.GetDefaultHtmlTag(PID, global.GetMenuTitle(PID, LANG_SET)));
				sw.WriteLine("<table id=\"report_table\" class=\"report\">");
				sw.WriteLine("<tr>");
				sw.WriteLine("<th>내용</th>");
				sw.WriteLine("<th>경과일</th>");
				sw.WriteLine("<th>결제일</th>");
				sw.WriteLine("<th>비고</th>");
				sw.WriteLine("<th>금액</th>");
				sw.WriteLine("</tr>");

				for (int i = 0; i < DataSetUtil.GetRowCount(ds, tableName); i++)
				{
					string contents = DataSetUtil.GetFldStr(ds, tableName, i, "Contents");
					string cnt = DataSetUtil.GetFldStr(ds, tableName, i, "Cnt");
					string bizDt = DataSetUtil.GetFldStr(ds, tableName, i, "Biz_Dt");
					string remark = DataSetUtil.GetFldStr(ds, tableName, i, "Remark");
					string amount = DataSetUtil.GetFldStr(ds, tableName, i, "Amount");

					sw.WriteLine("<tr>");
					sw.WriteLine("<td class=\"lbl\">" + contents + "</td>");
					sw.WriteLine("<td class=\"lbl_c\">" + cnt + "</td>");
					sw.WriteLine("<td class=\"lbl_c\">" + bizDt + "</td>");
					sw.WriteLine("<td class=\"lbl\">" + remark + "</td>");
					sw.WriteLine("<td class=\"data\">" + amount + "</td>");
					sw.WriteLine("</tr>");
				}
				sw.WriteLine("</table>");
				sw.WriteLine("<script type=\"text/javascript\" language=\"javascript\" defer=\"defer\">");
				sw.WriteLine("TableRowspan(report_table, '0');");
				sw.WriteLine("</script>");
				sw.WriteLine("</body>");
				sw.WriteLine("</html>");

				sw.Close();
			}
			catch (Exception e)
			{
				Base.AppFramework.SMEventLog.WriteExceptionLog(e);
				CallMsgBoxInAjax("MSG_ERR_122");	//파일을 생성하지 못했습니다
			}
		}

		#endregion		

		#endregion

		#region 디테일 Method (3, 4)

			#region 계정별챠트(당월)

		private void DrawThisMonthAccountChart()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_paymnt_dt", typeof(string), kw6);
			lo_dp.AddProperty("ls_exc_sys_id", typeof(Int32), kw4);
			lo_dp.AddProperty("ls_exc_prefix", typeof(Int32), kw5);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Crd2011r_NT _Crd2011r_NT = new Crd2011r_NT())
			{
				lo_ds.Merge(_Crd2011r_NT.GetMonthlyAmtListByAccount(lo_dp));
				int li_count = DataSetUtil.GetRowCount(lo_ds, "UPDMS_CRD_REPORT");

				for (int i = 0; i < li_count; i++)
				{
					//수동으로 데이터 바인딩
					chart_this_month_account.Data[0, i] = DataSetUtil.GetFldInt(lo_ds, "UPDMS_CRD_REPORT", i, "Total");

					//X축 라벨링
					chart_this_month_account.AxisX.Labels[i] = DataSetUtil.GetFldStr(lo_ds, "UPDMS_CRD_REPORT", i, "Account_Nm");
				}
			}
		}
		
			#endregion

			#region 미결제리스트

		//미결제리스트
		private void SetNotPaymentSummaryList()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_base_dt", typeof(string), kw6);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);
			
			using (Crd2013r_NT _Crd2013r_NT = new Crd2013r_NT())
			{
				lo_ds.Merge(_Crd2013r_NT.GetNotPaymentSummaryList(lo_dp));
			}
			tbl_not_payment_list.Visible = true;
			gv_not_payment_list.DataSource = lo_ds;
			gv_not_payment_list.DataBind();
		}

			#endregion

			#region 계정별전월대비증감액

		private void SetAccountList()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			
			string ls_pre_paymnt_dt;
			
			//이전달 - 첫달이면 계산해서 이전달을 설정, 아니면 ddl에서 가져옴.
			ls_pre_paymnt_dt = (ddl_paymnt_dt.SelectedIndex == 0)
								? DateUtil.GetCalcMonth(ddl_paymnt_dt.Items[0].ToString(), -1, "yyyy-MM-dd")  
								: ddl_paymnt_dt.Items[ddl_paymnt_dt.SelectedIndex - 1].ToString();
			
			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_pre_paymnt_dt", typeof(string), ls_pre_paymnt_dt);
			lo_dp.AddProperty("ls_this_paymnt_dt", typeof(string), kw6);
			lo_dp.AddProperty("ls_exc_sys_id", typeof(string), kw4);
			lo_dp.AddProperty("ls_exc_prefix", typeof(string), kw5);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Crd3010p_NT _Crd3010p_NT = new Crd3010p_NT())
			{
				lo_ds.Merge(_Crd3010p_NT.GetAccountList(lo_dp));
			}
			tbl_account_list.Visible = true;
			tbl_account_detail_list.Visible = true;
			gv_account_list.DataSource = lo_ds;
			gv_account_list.DataBind();
		}
		
			#endregion 
		
			#region 계정별상세리스트

		private void SetAccountDetailList()
		{
			DataSet lo_ds_max = new DataSet(); 
			DataSet lo_ds_nim = new DataSet();
			DataPack lo_dp = new DataPack();
			
			string ls_pre_paymnt_dt;
			string ls_account_max;
			string ls_account_min;

			//항목별리스트에 데이터가 있으면
			if (gv_account_list.Rows.Count > 0)
			{
				//가장많이 늘어난 항목
				ls_account_max = gv_account_list.DataKeys[0].Values["Account"].ToString();

				//가장많이 줄어든 항목
				ls_account_min = gv_account_list.DataKeys[gv_account_list.Rows.Count - 1].Values["Account"].ToString();

				//이전달
				ls_pre_paymnt_dt = (ddl_paymnt_dt.SelectedIndex == 0)
								? DateUtil.GetCalcMonth(ddl_paymnt_dt.Items[0].ToString(), -1, "yyyy-MM-dd")
								: ddl_paymnt_dt.Items[ddl_paymnt_dt.SelectedIndex - 1].ToString();

				lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
				lo_dp.AddProperty("ls_pre_paymnt_dt", typeof(string), ls_pre_paymnt_dt);
				lo_dp.AddProperty("ls_this_paymnt_dt", typeof(string), kw6);
				lo_dp.AddProperty("ls_exc_sys_id", typeof(string), kw4);
				lo_dp.AddProperty("ls_exc_prefix", typeof(string), kw5);
				lo_dp.AddProperty("ls_account", typeof(string));
				lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

				using (Crd3010p_NT _Crd3010p_NT = new Crd3010p_NT())
				{
					//가장많이 늘어난 항목
					lo_dp["ls_account"] = ls_account_max;
					lo_ds_max.Merge(_Crd3010p_NT.GetAccountDetailList(lo_dp));

					//가장많이 줄어든 항목
					lo_dp["ls_account"] = ls_account_min;
					lo_ds_nim.Merge(_Crd3010p_NT.GetAccountDetailList(lo_dp));
				}

				gv_account_detail_list.DataSource = lo_ds_max;
				gv_account_detail_list.DataBind();

				gv_account_detail_list_min.DataSource = lo_ds_nim;
				gv_account_detail_list_min.DataBind();
			}			
		}

		//계정별상세리스트
		private void SetAccountDetailList(GridView lo_gv, string ls_account)
		{
			DataPack lo_dp = new DataPack();
			DataSet lo_ds = new DataSet();
			string ls_pre_paymnt_dt;

			//이전달
			ls_pre_paymnt_dt = (ddl_paymnt_dt.SelectedIndex == 0)
							? DateUtil.GetCalcMonth(ddl_paymnt_dt.Items[0].ToString(), -1, "yyyy-MM-dd")
							: ddl_paymnt_dt.Items[ddl_paymnt_dt.SelectedIndex - 1].ToString();

			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_pre_paymnt_dt", typeof(string), ls_pre_paymnt_dt);
			lo_dp.AddProperty("ls_this_paymnt_dt", typeof(string), kw6);
			lo_dp.AddProperty("ls_exc_sys_id", typeof(string), kw4);
			lo_dp.AddProperty("ls_exc_prefix", typeof(string), kw5);
			lo_dp.AddProperty("ls_account", typeof(string), ls_account);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			//Base.AppFramework.SMEventLog.WriteDataLog("SetAccountDetailList - 1", lo_dp);
			
			try
			{
				using (Crd3010p_NT _Crd3010p_NT = new Crd3010p_NT())
				{
					lo_ds.Merge(_Crd3010p_NT.GetAccountDetailList(lo_dp));

					//Base.AppFramework.SMEventLog.WriteDataLog("SetAccountDetailList - 2", lo_ds.Tables["UPDMS_CRD_REPORT"]);
					
					lo_gv.DataSource = lo_ds;
					lo_gv.DataBind();
				}
			}
			catch(Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
		}
		
			#endregion
		
		#endregion

		#region CRUD (SearchProcess)

		//조회
		private void SelectProcess()
		{
			SetImportantItemList();
			DrawMonthlyTotalAmtChart();
			DrawMonthlyAccountChart();
			DrawThisMonthAccountChart();
		}

		//검색
		private void SearchProcess()
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();
			SelectProcess();

			//검색버튼 클릭시 다시 감추기 
			tbl_chart_this_month_account.Visible = false;
			tbl_not_payment_list.Visible = false;
			tbl_account_list.Visible = false;
			tbl_account_detail_list.Visible = false;
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP); //사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					//사용권한별 버튼처리
					PagePreRender.SetVisibleCtrl(this, access.CheckPgmUsingGrant(USER_DIV, PID), access.GetVisibleCtrl(PID));
				}
			}
			ChangePageMode();
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			switch (gs_page_mode)
			{
				case "":		//처음 페이지로드시
					Top.Visible = true;
					menu_area.Attributes.Add("class", "");
					ibtn_close.Visible = false;
					break;
				case "P":		//팝업으로 열때
					Top.Visible = false;
					menu_area.Attributes.Add("class", "nodisplay");
					ibtn_close.Visible = true;
					break;
			}
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region GridView이벤트

		//주요아이템
		protected void gv_important_item_list_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onMouseOver", GRID_ONMOUSEOVER_COLOR);
				e.Row.Attributes.Add("onMouseOut", GRID_ONMOUSEOUT_COLOR);

				//번호
				e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
			}

			//머지
			SMGridView sGv = new SMGridView(this.Page, ref gv_important_item_list);
			sGv.RowSpanGridView(gv_important_item_list, 1);
		}

		//미결제리스트
		protected void gv_not_payment_list_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				switch (gv.DataKeys[e.Row.RowIndex].Values["Biz_Div"].ToString())
				{
					case "BB001": //일시불총계
						e.Row.Attributes.Add("class", "total_v1");
						for (int i = 0; i < e.Row.Cells.Count; i++)
						{
							e.Row.Cells[i].Attributes.Add("class", "div_line_t_dbl");
						}
						break;
					case "BB002": //현금서비스총계
						e.Row.Attributes.Add("class", "total_v1");
						break;
					case "BB003": //할부총계
						e.Row.Attributes.Add("class", "total_v1");
						break;
					case "BB004": //월별총계
						e.Row.Attributes.Add("class", "total_v2");
						break;
					case "BB005": //총미결제액
						e.Row.Attributes.Add("class", "total_v3");
						break;
					default:
						//e.Row.Attributes.Add("style", "bg_white");
						break;
				}//switch
			}

			//머지
			SMGridView sGv = new SMGridView(this.Page, ref gv_not_payment_list);
			sGv.RowSpanGridView(gv_not_payment_list, 0);//카드명
			sGv.RowSpanGridView(gv_not_payment_list, 1);//결제일
		}
		
		//항목별리스트
		protected void gv_account_list_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onMouseOver", GRID_ONMOUSEOVER_COLOR);
				e.Row.Attributes.Add("onMouseOut", GRID_ONMOUSEOUT_COLOR);

				//증감
				string ls_attr = (e.Row.Cells[4].Text.Substring(0, 1) == "-") ? "color_blue" : "color_darkred";
				e.Row.Cells[4].Attributes.Add("class", ls_attr);
				
				//합계
				ld_pre_total += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Pre_Total"));
				ld_this_total += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "This_Total"));
				ld_diff_total += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Diff_Total"));
			}
			
			//Footer에 합계 바인딩
			if (e.Row.RowType == DataControlRowType.Footer)
			{
				e.Row.Cells[0].Visible = false;
				e.Row.Cells[1].Text = "Total";
				e.Row.Cells[1].Attributes.Add("class", "total");
				e.Row.Cells[2].Text = ld_pre_total.ToString("#,###,##0");
				e.Row.Cells[2].Attributes.Add("class", "money");
				e.Row.Cells[3].Text = ld_this_total.ToString("#,###,##0");
				e.Row.Cells[3].Attributes.Add("class", "money");
				e.Row.Cells[4].Text = ld_diff_total.ToString("#,###,##0");
				e.Row.Cells[4].Attributes.Add("class", "money");
			}			
		}

		//항목별상세리스트
		protected void gv_account_detail_list_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onMouseOver", GRID_ONMOUSEOVER_COLOR);
				e.Row.Attributes.Add("onMouseOut", GRID_ONMOUSEOUT_COLOR);

				//증감
				if (e.Row.Cells[5].Text.Substring(0, 1) == "-")
				{
					e.Row.Cells[5].Attributes.Add("class", "color_blue");
				}
				else
				{
					e.Row.Cells[5].Attributes.Add("class", "color_darkred");
				}
			}
			
			//머지
			SMGridView sGv = new SMGridView(this.Page, ref gv_account_detail_list);
			sGv.RowSpanGridView(gv_account_detail_list, 0);//지출구분
		}

		//항목별상세리스트
		protected void gv_account_detail_list_min_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onMouseOver", GRID_ONMOUSEOVER_COLOR);
				e.Row.Attributes.Add("onMouseOut", GRID_ONMOUSEOUT_COLOR);

				//증감
				if (e.Row.Cells[5].Text.Substring(0, 1) == "-")
				{
					e.Row.Cells[5].Attributes.Add("class", "color_blue");
				}
				else
				{
					e.Row.Cells[5].Attributes.Add("class", "color_darkred");
				}
			}

			//머지
			SMGridView sGv = new SMGridView(this.Page, ref gv_account_detail_list_min);
			sGv.RowSpanGridView(gv_account_detail_list_min, 0);//지출구분
		}

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}

		//계정별전월대비증감액에서 계정 클릭시
		protected void lbtn_set_account_detail_list_Click(object sender, EventArgs e)
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();
			
			GridView lo_gv = new GridView();
			lo_gv = (h_gridview.Value == "PLUS") ? gv_account_detail_list : gv_account_detail_list_min;

			SetAccountDetailList(lo_gv, h_account.Value);
		}

		//계정별챠트(당월)
		protected void lbtn_chart_this_month_account_Click(object sender, EventArgs e)
		{
			tbl_chart_this_month_account.Visible = true;
		}

		//미결제리스트
		protected void lbtn_not_payment_list_Click(object sender, EventArgs e)
		{
			if (!tbl_not_payment_list.Visible)
			{
				lbl_search_flag.Text = "SEARCH";
				SetSearchParameter();

				SetNotPaymentSummaryList();
			}
		}

		//계정별전월대비증감액
		protected void lbtn_account_list_Click(object sender, EventArgs e)
		{
			if (!tbl_account_list.Visible)
			{
				lbl_search_flag.Text = "SEARCH";
				SetSearchParameter();

				SetAccountList();
				SetAccountDetailList();
			}
		}

		//FTP
		protected void ibtn_ftp_Click(object sender, EventArgs e)
		{
			string fileName = PID + ".html";
			FtpClient fc = new FtpClient(FTP_HOSTNAME, FTP_USERID, crypto.Decrypt(FTP_PASSWORD));

			try
			{
				DataSet lo_ds = new DataSet();

				using (Crd3010p_NT _Crd3010p_NT = new Crd3010p_NT())
				{
					lo_ds.Merge(_Crd3010p_NT.GetImportantItemList());
				}
				//파일생성
				CreateFileReal(fileName, lo_ds);

				//FTP전송
				if (FileUtil.IsFileExist(FILE_PATH_FTP_UPLOAD + "\\" + fileName))
				{
					fc.Login();
					fc.BinaryMode = false;

					string[] remoteDir = StringUtil.DelimitedListToStringArray(FTP_DIR_IPHONE_CRD, "/");
					for (int i = 0; i < remoteDir.Length; i++)
					{
						fc.ChangeDir(remoteDir[i]);
					}

					if (fc.IsFileExist(fileName))
					{
						fc.DeleteFile(fileName);
					}

					fc.UploadOnlyFile(FILE_PATH_FTP_UPLOAD, fileName, "", "", true);
					fc.Close();
				}
				else
				{
					CallMsgBoxInAjax("MSG_ERR_164");	//전송할 파일이 없습니다.
				}
				CallMsgBoxInAjax("MSG_INF_018");	//전송되었습니다
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
			finally
			{
				fc.Close();
			}
		}
		
		#endregion

	}
}
